package com.xian.im.web.modules.sys;

import com.xian.im.common.result.RestResult;
import com.xian.im.common.result.RestResultBuilder;
import com.xian.im.modules.mis.BlackProcess;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

/**
 * @program: xian-im-server
 * @description:
 * @author: liru.xian
 * @create: 2021-02-03 10:21
 **/
@RestController
@RequestMapping("im/black")
@Api(value = "IP黑名单", tags = {"IP黑名单"})
public class SystemBlackController {

    @Autowired
    private BlackProcess blackProcess;


    @ApiOperation(value = "清理指定IP", notes = "清理指定IP")
    @RequestMapping(value = "clear/{ipAddress}",method = RequestMethod.GET)
    public RestResult<Boolean> clear(@PathVariable("ipAddress") String ipAddress){
        blackProcess.remove(ipAddress);
        return RestResultBuilder.builder().success(true).build();
    }

    @ApiOperation(value = "获取所有", notes = "获取所有")
    @RequestMapping(value = "all",method = RequestMethod.GET)
    public RestResult<Set<String>> clear(){
        Set<String> all = blackProcess.getAll();
        return RestResultBuilder.builder().success(all).build();
    }
}
